package com.ktgj.service.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.service.domain.ContractLinkActivitycode;
import com.ktgj.service.service.IContractLinkActivitycodeService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 活动码批次明细Controller
 * 
 * @author ruoyi
 * @date 2021-09-03
 */
@ControllerAdvice
@RestController
@RequestMapping("/activitycode")
public class ContractLinkActivitycodeController extends BaseController
{
    @Autowired
    private IContractLinkActivitycodeService contractLinkActivitycodeService;

    /**
     * 查询活动码批次明细列表
     */
    //@PreAuthorize(hasPermi = "service:activitycode:list")
    @GetMapping("/list")
    public TableDataInfo list(ContractLinkActivitycode contractLinkActivitycode)
    {
        startPage();
        List<ContractLinkActivitycode> list = contractLinkActivitycodeService.selectContractLinkActivitycodeList(contractLinkActivitycode);
        return getDataTable(list);
    }

    /**
     * 导出活动码批次明细列表
     */
    @PreAuthorize(hasPermi = "service:activitycode:export")
    @Log(title = "活动码批次明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractLinkActivitycode contractLinkActivitycode) throws IOException
    {
        List<ContractLinkActivitycode> list = contractLinkActivitycodeService.selectContractLinkActivitycodeList(contractLinkActivitycode);
        ExcelUtil<ContractLinkActivitycode> util = new ExcelUtil<ContractLinkActivitycode>(ContractLinkActivitycode.class);
        util.exportExcel(response, list, "活动码批次明细数据");
    }

    /**
     * 获取活动码批次明细详细信息
     */
    @PreAuthorize(hasPermi = "service:activitycode:query")
    @GetMapping(value = "/{linkId}")
    public AjaxResult getInfo(@PathVariable("linkId") Long linkId)
    {
        return AjaxResult.success(contractLinkActivitycodeService.selectContractLinkActivitycodeById(linkId));
    }

    /**
     * 新增活动码批次明细
     */
    @PreAuthorize(hasPermi = "service:activitycode:add")
    @Log(title = "活动码批次明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractLinkActivitycode contractLinkActivitycode)
    {
        return toAjax(contractLinkActivitycodeService.insertContractLinkActivitycode(contractLinkActivitycode));
    }

    /**
     * 修改活动码批次明细
     */
    @PreAuthorize(hasPermi = "service:activitycode:edit")
    @Log(title = "活动码批次明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractLinkActivitycode contractLinkActivitycode)
    {
        return toAjax(contractLinkActivitycodeService.updateContractLinkActivitycode(contractLinkActivitycode));
    }

    /**
     * 删除活动码批次明细
     */
    @PreAuthorize(hasPermi = "service:activitycode:remove")
    @Log(title = "活动码批次明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkIds}")
    public AjaxResult remove(@PathVariable Long[] linkIds)
    {
        return toAjax(contractLinkActivitycodeService.deleteContractLinkActivitycodeByIds(linkIds));
    }
}
